package moltencore.network.protocol;

import spark.network.Util;
import spark.network.protocol.Base;
import spark.network.protocol.Response;

public class GameListSendingEnd extends Base {
	public static final short TYPE = 0x17;
	private static final byte[] TYPE_BYTES = Util.makeBytes(TYPE);

	private int numOfSentPackets;
	private static final int SENT_PACKETS_NUM_OFFSET = Base.SIZE;
	private static final int SENT_PACKETS_NUM_LENGTH = Integer.SIZE / 8;

	private static final int SIZE =
		Base.SIZE +
		SENT_PACKETS_NUM_LENGTH;

	public GameListSendingEnd() {
		super(true, TYPE_BYTES);
	}

	public GameListSendingEnd(int numOfSentPackets) {
		super(true, TYPE_BYTES);
		this.numOfSentPackets = numOfSentPackets;
	}

	public int getNumOfSentPackets(){
		return numOfSentPackets;
	}

	public void setNumOfSentPackets(int numOfSentPackets){
		this.numOfSentPackets = numOfSentPackets;
	}

	@Override
	public void fill(byte[] buffer) {
		super.fill(buffer);
		numOfSentPackets = Util.makeInt(buffer, SENT_PACKETS_NUM_OFFSET);
	}

	@Override
	public void getBytes(byte[] buffer) {
		super.getBytes(buffer);
		Util.arraycopy(Util.makeBytes(numOfSentPackets), 0, buffer, SENT_PACKETS_NUM_OFFSET);
	}

	@Override
	public int getSize() {
		return SIZE;
	}

	public static GameListSendingEnd create(byte[] buffer, long receiveTime){
		GameListSendingEnd packet = new GameListSendingEnd();
		packet.fill(buffer);
		packet.setTimeStampReceive(receiveTime);
		return packet;
	}
}
